﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data.Entity;

namespace FG_Admin_DAL
{
    public class NewsDAL
    {
        FGSkiingEntities model = new FGSkiingEntities();
        /// <summary>
        /// 返回所有新闻信息
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public List<News> GetNews(int PageIndex, int PageSize)
        {
            return model.News.OrderBy(p => p.NewsID).OrderBy(p=>p.NewsID).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
        }
        /// <summary>
        /// 返回新闻类别对应的新闻信息
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="NewsType">新闻类别</param>
        /// <returns></returns>
        public List<News> GetNews(int PageIndex, int PageSize,int NewsType)
        {
            return model.News.Where(p => p.NewsType == NewsType).OrderBy(p=>p.NewsID).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="Title">新闻标题</param>
        /// <param name="NewsType">新闻类别</param>
        /// <returns></returns>
        public List<News> GetNews(int PageIndex, int PageSize, string Title,int NewsType)
        {
            return model.News.Where(p => NewsType==0?true:p.NewsType==NewsType && p.NewsTitle.Contains(Title)).OrderBy(p => p.NewsID).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
        }        /// <summary>
        /// 添加新闻信息
        /// </summary>
        /// <param name="ss"></param>
        /// <returns></returns>
        public int AddNews(News ss)
        {
            model.News.Add(ss);
            return model.SaveChanges();
        }
    }
}
